package com.paul.inventoryitem.dao;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.paul.base.dao.BaseDao;
import com.paul.inventoryitem.valueobject.InventoryItem;

@Stateless
@LocalBean
public class InventoryItemDao2 extends BaseDao<InventoryItem>{
	
	@PersistenceContext(unitName = "test_pu2")
	private EntityManager entityManager;

	public InventoryItemDao2() {
		super(InventoryItem.class);
	}

	@Override
	protected EntityManager getEntityManager() {
		return entityManager;
	}
	
	public void createWithException(InventoryItem inventoryItem)
	{
		super.create(inventoryItem);
		int i = 1/0;
	}
	
	public void createWithoutException(InventoryItem inventoryItem)
	{
		super.create(inventoryItem);
	}
	
	public void createCombine(InventoryItem inventoryItem)
	{
		this.createWithoutException(inventoryItem);
		InventoryItem inventoryItem2 = new InventoryItem();
		inventoryItem2.setFutureDate(inventoryItem.getFutureDate());
		inventoryItem2.setLowerCaseName(inventoryItem.getLowerCaseName());
		inventoryItem2.setMail(inventoryItem.getMail());
		inventoryItem2.setMinimumPrice(inventoryItem.getMinimumPrice());
		inventoryItem2.setMustBeTrue(true);
		inventoryItem2.setName(inventoryItem.getName());
		inventoryItem2.setPrice(inventoryItem.getPrice());
		this.createWithException(inventoryItem2);
	}

}
